#!/bin/bash
BRANCH=trunk
VERSION="0.6.0-SNAPSHOT"
TARGET=wicketcool-$VERSION

#clear
echo "#####   CLEAR  ####"
rm -rf build
rm -rf $TARGET

# checkout project
echo "#####   CHECKOUT  ####"
svn checkout http://wicketcool.googlecode.com/svn/$BRANCH build 

# create target folder
echo "#####   CREATING TARGET  ####"
mkdir $TARGET
cp ./README.txt ./$TARGET/README.txt
cd $TARGET
mkdir repo
cd repo
mkdir repository
mkdir repository/pl
mkdir repository/pl/rabbitsoftware
mkdir repository/pl/rabbitsoftware/wctemplate-archetype
cd ..
mkdir bin
cd ..

# assembly wicketcool jar
echo "#####   WICKETCOOL ASSEMBLY  ####"
cd ./build/wicketcool/wicketcool.commandline 
mvn clean install assembly:assembly
cd ../../..
cp ./build/wicketcool/wicketcool.commandline/target/wicketcool.commandline-$VERSION-jar-with-dependencies.jar ./$TARGET/bin/wicketcool.commandline.jar
cp wcl ./$TARGET/bin/wcl
cp wcl.bat ./$TARGET/bin/wcl.bat

# build archetype
echo "#####   BUILDING ARCHETYPE  ####"
cd ./build/wctemplate
mvn clean
rm create-archetype.sh
mvn archetype:create-from-project -Darchetype.filteredExtensions=java
cd ./target/generated-sources/archetype
mvn clean install
cd ../../../../../
cp ~/.m2/archetype-catalog.xml ./$TARGET/repo
cp ~/.m2/repository/pl/rabbitsoftware/wctemplate-archetype/maven-metadata-local.xml ./$TARGET/repo/repository/pl/rabbitsoftware/wctemplate-archetype/
cp -R ~/.m2/repository/pl/rabbitsoftware/wctemplate-archetype/$VERSION ./$TARGET/repo/repository/pl/rabbitsoftware/wctemplate-archetype/$VERSION

echo "#####   FINISHED  ####"
